home *** CD-ROM | disk | FTP | other *** search
/ The Ultimate Millenium Investment Guide / Hargreaves Lansdown - The Ultimate Millenium Investment Guide (IG).ISO / mac / Xtras / DirectMedia / DirectMedia Xtra Behaviours.cst / 00008_Script_Volume slider < prev    next >
Text File  |  1998-09-03  |  9KB  |  253 lines

  1. -- DirectMedia Xtra Volume Slider
  2.  
  3.  
  4. -- based on the Video Time Slider from the behavior library version 1.1
  5. -- Control
  6.  
  7. -- requires an 'extent' cast member 
  8. -- that limits the range the slider 'slides'
  9. -- controls the currenttime of a DirectMedia Xtra sprite,
  10. -- if the sprite is playing the slider moves automatically
  11.  
  12.  
  13.  
  14. property pDuration, pMovieTime, VideoSprite
  15.  
  16. property horizontal  -- if false, vertical
  17. property extentSprite
  18. property hiliteMember  -- looks like the handle plus hilite graphics
  19. -- also holds the member of handle while hilited
  20.  
  21. property tracking
  22. property newLocH
  23. property newLocV
  24.  
  25. property sending   -- if true, sends value when parked
  26. property dynamic   -- if true and sending true, sends value while tracking
  27. property style     -- [sendAllSprites, SendSprite, Call]
  28. property addressee -- which spritenum gets the message if SendSprite or Call
  29. property name      -- Sliders identity so messages can be traced
  30. property notify_list -- list of sprites to receive event, only has 1 item this time
  31.  
  32. property min, max  -- the range the slider maps to
  33. property valrange  -- the difference of max and min, set on begin
  34. property minScreen, maxScreen -- calculated from the screen coords of the extent
  35. property currentScreenVal -- the data point in screen coords, set in tracking
  36. property extentlength -- in screen coords, set on begin
  37.  
  38. property CurrentVal
  39.  
  40. on getPropertyDescriptionList
  41.   if the currentspritenum = 0 then 
  42.     set memdefault = 0 
  43.   else
  44.     set memref = the member of sprite the currentspritenum
  45.     set castlibnum = the castlibnum of memref
  46.     set memdefault = member (the membernum of member memref + 1) of castlib castlibnum
  47.   end if
  48.   
  49.   
  50.   set description = [:]
  51.   
  52.   addprop description, #VideoSprite, [#default: 1, #format:#integer, #comment: "Video Sprite:"]
  53.   
  54.   addprop description, #extentSprite, [#default: 1, #format:#integer, #comment: "Extent Sprite:"]
  55.   
  56.   addprop description, #hiliteMember, [#default: memdefault , #format:#graphic,#comment: "Hilite Member:"]
  57.   
  58.   addprop description, #horizontal, [#default: 1, #format:#boolean,#comment: "Horizontal (if not vertical):"]
  59.   
  60.   addprop description, #dynamic, [#default: 1, #format:#boolean,#comment: "Dynamic:"]
  61.   
  62.   return description
  63. end
  64.  
  65. on getBehaviorDescription
  66.   return "Drag to slider 'handle' to enable control of video play time.  Requires additional 'extent' member which limits the handle travel range." & RETURN & "PARAMETERS:" & RETURN & "ò Video Sprite - Enter the number of sprite channel in which video is displayed." & RETURN & "ò Extent Sprite -  Enter the number of sprite channel that contains the 'extent' sprite."  & RETURN & "ò Hilite Member -  Member to display while handle is being dragged."  & RETURN & "ò Horizontal - If set, orient extent sprite horizontally, if not set orient vertically."  & RETURN & "ò Dynamic - If set, video time will be updated while handle is dragged, else when handle is released."
  67. end
  68.  
  69. on compute_val me
  70.   -- relies on tracking to update the currentScreenVal (different for Hor, Vert)
  71.   set val = 0.0
  72.   set val = float(the currentScreenVal of me) / float (the extentlength of me)
  73.   set val = val * the valrange of me
  74.   set val = val + the min of me
  75.   return val
  76. end
  77.  
  78. on send_the_val me, val
  79.   -- sets the digital video volume to the val * paramter 
  80.   set pMovieTime = val * pDuration
  81.   setvolume(sprite VideoSprite, pMovieTime-100)
  82. end
  83.  
  84.  
  85. on beginSprite me
  86.   
  87.   set pDuration = 100
  88.   
  89.   set the min of me = 0.0
  90.   set the max of me = 1.0
  91.   set the sending of me = true
  92.   
  93.   --
  94.   set handle = the spritenum of me
  95.   set the tracking of me = FALSE
  96.   set the newLocH of me = the locH of sprite handle
  97.   set the newLocV of me = the locV of sprite handle
  98.   
  99.   if the horizontal of me then    
  100.     set the newLocV of me = the locV of sprite the extentSprite of me
  101.     set the minScreen of me = the left of sprite the extentSprite of me
  102.     set the maxScreen of me = the right of sprite the extentSprite of me
  103.   else -- vertical slider
  104.     set the newLocH of me = the locH of sprite the extentSprite of me  
  105.     set the minScreen of me = the left of sprite the extentSprite of me
  106.     set the maxScreen of me = the right of sprite the extentSprite of me
  107.   end if
  108.   
  109. --  puppetsprite handle, TRUE  -- take this out when beginSpriteAutoPuppet fixed
  110.   
  111.   set the locH of sprite handle to the newLocH of me
  112.   set the locV of sprite handle to the newLocV of me
  113.   
  114.   set the valrange of me = the max of me - the min of me
  115.   set the extentlength of me = the maxScreen of me - the minScreen of me
  116.   
  117.   if the sending of me = FALSE then  -- check for wrong input (dyn true, send false)
  118.     set the dynamic of me = FALSE
  119.   end if
  120.   
  121.   -- set CurrentVal =  compute_val() 
  122.   
  123. end
  124.  
  125. on prepareFrame me
  126.   -- limits motion of handle to extents of extentSprite
  127.   -- and locks the handle to the track of the extentSprite
  128.   
  129.   if tracking then
  130.     set handle = the spriteNum of me
  131.     set extent =  the extentSprite of me
  132.     
  133.     if the horizontal of me then    
  134.       set the newLocH of me = the mouseH
  135.       set the newLocV of me = the locV of sprite extent
  136.       if the newLocH of me < the left of sprite extent then
  137.         set the newLocH of me = the left of sprite extent
  138.       end if
  139.       if the newLocH of me > the right of sprite extent then
  140.         set the newLocH of me = the right of sprite extent
  141.       end if
  142.       
  143.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  144.       
  145.     else -- vertical slider
  146.       set the newLocH of me = the locH of sprite extent
  147.       set the newLocV of me = the mouseV
  148.       if the newLocV of me < the top of sprite extent then
  149.         set the newLocV of me = the top of sprite extent
  150.       end if
  151.       if the newLocV of me > the bottom of sprite extent then
  152.         set the newLocV of me = the bottom of sprite extent
  153.       end if   
  154.       
  155.       set the currentScreenVal of me = the newLocV of me - the minScreen of me
  156.       
  157.     end if  -- if vertical
  158.     
  159.     set the locH of sprite handle to the newLocH of me
  160.     set the locV of sprite handle to the newLocV of me
  161.     
  162.     if the dynamic of me then
  163.       send_the_val me, compute_val (me)
  164.     end if
  165.     
  166.   else   --  end if tracking, control slider position by movieTime
  167.     
  168.     set x = float(getvolume(sprite VideoSprite)+100)/ float(pDuration)
  169.     
  170.     
  171.     set handle = the spriteNum of me
  172.     set extent =  the extentSprite of me
  173.     
  174.     if the horizontal of me then
  175.       set ScreenX = the left of sprite extent + (x * (the right of sprite extent - the left of sprite extent))
  176.       set the newLocH of me = screenX
  177.       set the newLocV of me = the locV of sprite extent
  178.       if the newLocH of me < the left of sprite extent then
  179.         set the newLocH of me = the left of sprite extent
  180.       end if
  181.       if the newLocH of me > the right of sprite extent then
  182.         set the newLocH of me = the right of sprite extent
  183.       end if
  184.       
  185.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  186.       
  187.     else -- vertical slider
  188.       set ScreenY = the top of sprite extent + (x * (the bottom of sprite extent - the top of sprite extent))
  189.       set the newLocH of me = the locH of sprite extent
  190.       set the newLocV of me = ScreenY
  191.       if the newLocV of me < the top of sprite extent then
  192.         set the newLocV of me = the top of sprite extent
  193.       end if
  194.       if the newLocV of me > the bottom of sprite extent then
  195.         set the newLocV of me = the bottom of sprite extent
  196.       end if   
  197.       
  198.       set the currentScreenVal of me = the newLocV of me - the minScreen of me
  199.       
  200.     end if  -- if vertical
  201.     
  202.     set the locH of sprite handle to the newLocH of me
  203.     set the locV of sprite handle to the newLocV of me
  204.     
  205.   end if
  206.   
  207.   
  208. end
  209.  
  210. on mouseDown me 
  211.   set tracking = TRUE
  212.   set temp = the member of sprite the spritenum of me
  213.   set the member of sprite the spritenum of me = member the hiliteMember of me
  214.   set the hiliteMember of me = temp
  215. end
  216.  
  217. on mouseUp me
  218.   set tracking = FALSE
  219.   set temp = the member of sprite the spritenum of me
  220.   set the member of sprite the spritenum of me = member the hiliteMember of me
  221.   set the hiliteMember of me = temp
  222.   
  223.   if the sending of me then
  224.     set x = compute_val (me)
  225.     send_the_val me, x
  226.   end if
  227.   
  228. end
  229.  
  230. on mouseUpOutside me
  231.   set tracking = FALSE
  232.   set temp = the member of sprite the spritenum of me
  233.   set the member of sprite the spritenum of me = member the hiliteMember of me
  234.   set the hiliteMember of me = temp
  235.   
  236.   if the sending of me then
  237.     set x = compute_val (me)
  238.     send_the_val me, x
  239.   end if
  240.   
  241. end
  242.  
  243. on mouseEnter me
  244.   
  245. end
  246.  
  247. on mouseLeave me
  248.   
  249. end
  250.  
  251.  
  252.  
  253.